
#include <QDebug>

#include "sourcesdata.h"

static bool registered = false;

SourcesData::SourcesData(QObject *parent) : QObject{parent}
{
    Initialization();
}

SourcesData::SourcesData(const SourcesData &src, QObject *parent) : QObject{parent}
{
    Initialization();
    Copy(src);
}

SourcesData::~SourcesData()
{
}

SourcesData &SourcesData::operator=(const SourcesData &src)
{
    Initialization();
    return Copy(src);
}

bool SourcesData::operator==(const SourcesData &dst) const
{
    if (this->type != dst.type) { return false; }
    if (this->archs != dst.archs) { return false; }
    if (this->sign != dst.sign) { return false; }
    if (this->url != dst.url) { return false; }
    if (this->codename != dst.codename) { return false; }
    if (this->repos != dst.repos) { return false; }

    return true;
}

QString SourcesData::toSourcesList() const
{
    QStringList items;
    items << type;
    if (!archs.isEmpty()) {
        if (sign.isEmpty()) {
            items << QString("[arch=%1]").arg(archs.join(","));
        } else {
            items << QString("[arch=%1 signed-by=%2]").arg(archs.join(","), sign);
        }
    }
    items << url;
    items << codename;
    items << repos.join(" ");

    return items.join(" ");
}

void SourcesData::Initialization()
{
    if (!registered) {
        //RegisterMetaTypes(SourcesData);
        registered = true;
    }
}

SourcesData &SourcesData::Copy(const SourcesData &src)
{
    this->type = src.type;
    this->archs = src.archs;
    this->sign = src.sign;
    this->url = src.url;
    this->codename = src.codename;
    this->repos = src.repos;

    return *this;
}
